//
//  RMDataModelTool.m
//  RunningMan
//
//  Created by dllo on 16/5/26.
//  Copyright © 2016年 WSJ. All rights reserved.
//

#import "RMDataModelTool.h"

@implementation RMDataModelTool


+(void)archiveRMDataModelInPlist:(RMDataModel *)dataModel{
    
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *documentPath = [path stringByAppendingPathComponent:@"runman.plist"];
    NSMutableArray *arr = [NSKeyedUnarchiver unarchiveObjectWithFile:documentPath];
    NSLog(@"%@", documentPath);
    
    if (arr == nil) {
        arr = [NSMutableArray array]; //---------
    }
    [arr addObject:dataModel];
    [NSKeyedArchiver archiveRootObject:arr toFile:documentPath];
    
    
}

+(void)cancelRMDataModelInPlist{
    
    
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *documentPath = [path stringByAppendingPathComponent:@"runman.plist"];
    
    NSMutableArray *arr = [NSKeyedUnarchiver unarchiveObjectWithFile:documentPath];
    
    [arr removeAllObjects];
    NSLog(@"88888888%@", arr);
    [NSKeyedArchiver archiveRootObject:arr toFile:documentPath];
    
    
}

+(NSMutableArray *)getArray{
    
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *documentPath = [path stringByAppendingPathComponent:@"runman.plist"];
    
    NSMutableArray *arr = [NSKeyedUnarchiver unarchiveObjectWithFile:documentPath];
    
    return arr;
}




@end
